package dao;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import pojo.Cliente;

/**
 *
 * @author Vanessinha
 */
@Stateless
public class ClienteDao {

    @PersistenceContext(unitName = "LojaFilmesPU")
    private EntityManager em;

    public Cliente inserir(Cliente obj) {
        synchronized (this) {
            em.merge(obj);
        }
        return obj;

    }

    public Cliente pesquisar(Long obj) {
        return em.find(Cliente.class, obj);
    }

    public void excluir(Cliente obj) {
        Object objeto = em.merge(obj);
        em.remove(objeto);
    }

    public List<Cliente> getAll() {
        try {
            Query q = em.createQuery("select cliente from Cliente as cliente");
            return q.getResultList();
        } catch (Exception e) {
            System.out.println("Excecao cliente HQL.." + e);
            return null;
        }
    }
}
